package com.cjj.volatile_thread;

class VolatileDemo extends Thread{

    public volatile boolean flag = true;

    @Override
    public void run() {
        System.out.println("子线程开始执行----");
        while (flag){

        }
        System.out.println("子线程结束执行----");
    }

    public void isRun(boolean flag){
        this.flag = flag;
    }

}

/**
 * @ClassName VolatileThread
 * @Date 2021/07/18 19:21:00
 * @Created by ccc-j
 * @email ccc-ju@outlook.com
 */
public class VolatileThread {

    public static void main(String[] args) throws InterruptedException {
        VolatileDemo t1 = new VolatileDemo();
        t1.start();
        Thread.sleep(300);
        t1.isRun(false);
        System.out.println(t1.flag);
    }

}
